/**
 * @author 黄波
 * 创建日期：2011Sep 4, 2011
 * TODO// N/A
 */
package com.platform.dev.action;

import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.platform.constant.ResponseCode;
import com.platform.dev.bo.DevBo;
import com.platform.pojo.Module;

//更新模块信息
public class UpdateModuleAction extends DevSupport {

	private String id;
	private Module module;
	private String msg;
	private boolean success;
	/**
	 * @return the module
	 */
	public Module getModule() {
		return module;
	}
	/**
	 * @param module the module to set
	 */
	public void setModule(Module module) {
		this.module = module;
	}
	/**
	 * @return the msg
	 */
	public String getMsg() {
		return msg;
	}
	/**
	 * @param msg the msg to set
	 */
	public void setMsg(String msg) {
		this.msg = msg;
	}
	/**
	 * @return the success
	 */
	public boolean isSuccess() {
		return success;
	}
	/**
	 * @param success the success to set
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}
	@Override
	public String execute() throws Exception {
		if(id == null || id.equals("")) {
			msg = ResponseCode.FAILURE_ID_NULL;
		} else { 
			if(module != null) {
				if(module.getSuperId() == null) {
					module.setSuperId(0);
				}
				module.setId(Integer.parseInt(id));
				DevBo bo = new DevBo();
				if(bo.updateModule(module)) {
					msg = "更新成功！";
				} else {
					msg = "更新失败，数据库错误！";
				}
			} else {
				msg = "更新失败，提交内容为空！";
			}
		}
		success = true;
		HashMap map = new HashMap();
		map.put("msg", msg);
		map.put("success", success);
		JSONObject jsonObj = JSONObject.fromObject(map);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = response.getWriter();
		response.setCharacterEncoding("utf-8");
		out.println(jsonObj.toString());
		out.flush();
		return null;
	}
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	
	
}
